package view.test;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import model.GameModel;
import model.IGameModelObserver;
import controller.BankType;
import controller.GameController;

public class BinBank extends JLabel implements IGameModelObserver {

	protected static final long serialVersionUID = 6862719047626794975L;
	protected ImageIcon bankIcon;
	protected BankType bankType;
	protected GameModel model;
	protected Color color;
	
	// too many params here.. we should clean this up with a context or something
	public BinBank(GameModel model, GameController controller, BankType type, Color color, ImageIcon sprite, GlassPane pane) {
		this.bankType = type;
		this.model = model;				
		this.color = color;
		this.bankIcon = sprite;
		this.setBackground(color);
		this.setForeground(Color.WHITE);
		this.setFont(getFont().deriveFont(20f));
		this.setHorizontalAlignment(JLabel.CENTER);
		this.setBorder(BorderFactory.createLoweredBevelBorder());
		this.setIcon(sprite);
				
		BankMouseInputListener listener = new BankMouseInputListener(controller, this, pane);
		this.addMouseListener(listener);
		this.addMouseMotionListener(listener);
		model.registerWithModel(this);
		
		this.setOpaque(true);
	}
	public ImageIcon getEntityIcon() {
		return bankIcon;
	}
	public void setBankIcon(ImageIcon entityIcon) {
		this.setIcon(entityIcon);
		this.bankIcon = entityIcon;
	}
	public BankType getBankType() {
		return bankType;
	}
	
	private void setCount() {
		if (bankType == BankType.MIRROR) {
			this.setText(String.valueOf(model.getBin().getMirrorCount()));
			return;
		}
		
		switch(bankType) {
		case SOURCE : 
			if (color == Color.RED) {
				this.setText(String.valueOf(model.getBin().getRedSourceCount()));break;
			}
			else if (color == Color.GREEN) {
				this.setText(String.valueOf(model.getBin().getGreenSourceCount()));break;
			}
			else if (color == Color.BLUE) {
				this.setText(String.valueOf(model.getBin().getBlueSourceCount()));break;
			}
		
			default : ; // do nothing
			
		}				
	}
	@Override
	public void onGameModelChange() {
		setCount();
	}
	protected GameModel getModel() {
		return model;
	}
	protected Color getColor() {
		return color;
	}
	protected ImageIcon getBankIcon() {
		return bankIcon;
	}
	
}
